#include "AssetObject.h"
#include <cassert>

#include "Object/RootObject.h"
#include "Object/ObjectPathUtils.h"

RAssetObject::RAssetObject()
{
    assert( GetOwner()==WH::GetRootObject() && "Asset object's owner must be root object");
   
}

CString RAssetObject::CreateName(const SAssetPath & InPath)
{
    return CreateName(InPath.GetAssetType(), InPath.GetPackageName(), InPath.GetFolderPathInPackage(), InPath.GetAssetName());
}

CString RAssetObject::CreateName(CClass *InAssetType, const CString &InPackageName, const CString &InFolderPathInPackage, const CString &InAssetName)
{
    return InAssetType->GetFullName() 
        + WH::AssetPathSeparator +InPackageName
        + WH::AssetPathSeparator +InFolderPathInPackage
        + WH::AssetPathSeparator +InAssetName;    
}

CString RAssetObject::CreatePath(const SAssetPath & InPath)
{
    return WH::GetRootObject()->GetNodeName() + WH::ObjectPathSeparator + CreateName(InPath);
}

CString RAssetObject::CreatePath(CClass *InAssetType, const CString &InPackageName, const CString &InFolderPathInPackage, const CString &InAssetName)
{
    return WH::GetRootObject()->GetNodeName() + WH::ObjectPathSeparator + CreateName(InAssetType, InPackageName, InFolderPathInPackage, InAssetName);
}

CString RAssetObject::CreateThumnailPath(const SAssetPath &InPath)
{
    return CreatePath(InPath) +WH::AssetPathSeparator+ U"EngineEditorThumbnail";
}

const SAssetPath *RAssetObject::GetAssetPath() const
{
    return &Path;
}

TSharedObjectPtr<RAssetObject> RAssetObject::GetAssetObject(TSharedObjectPtr<RObject> InObject)
{
    if(InObject->IsA<RAssetObject>())
    {
        return InObject;
    }

    auto Parent = InObject->GetOwner();
    if(Parent)
    {
        return GetAssetObject(InObject->GetOwner());
    }
    
    return nullptr;
    
}
